import { createRouter, createWebHistory } from "vue-router";

import Layout from "../components/Layout/index.vue";

// 开启历史模式
const routerHistory = createWebHistory();

const routes = [
  {
    path: "/login",
    component: () => import("../views/login.vue"),
  },
  {
    path: "/test",
    component: () => import("../views/test.vue"),
  },
  {
    path: "/",
    redirect: "/plan/daily",
  },
  {
    path: "/plan",
    component: Layout,
    children: [
      {
        path: "/plan/daily",
        component: () => import("../views/plan/daily.vue"),
      },
      {
        path: "/plan/weekly",
        component: () => import("../views/plan/weekly.vue"),
      },
      {
        path: "/plan/yearly",
        component: () => import("../views/plan/yearly.vue"),
      },
    ],
  },
  {
    path: "/common",
    component: Layout,
    children: [
      {
        path: "/common/suggestion",
        component: () => import("../views/suggestion/index.vue"),
      },
      {
        path: "/common/suggestion/detail",
        component: () => import("../views/suggestion/detail.vue"),
      },
    ],
  },
  {
    path: "/knowledge",
    component: Layout,
    children: [
      {
        path: "/knowledge/interview",
        component: () => import("../views/interview/index.vue"),
      },
      {
        path: "/knowledge/canvas",
        component: () => import("../views/studyModule/canvas/index.vue"),
      },
      {
        path: "/knowledge/file/upload",
        component: () => import("../views/studyModule/fileUpload/index.vue"),
      },
    ],
  },
  {
    path: "/hot",
    component: Layout,
    children: [
      {
        path: "/hot/list",
        component: () => import("../views/hot/list.vue"),
      },
    ],
  },
];

const router = createRouter({
  history: routerHistory,
  routes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    } else {
      return { x: 0, y: 0 };
    }
  },
});

export default router;
